import sys
import os
from PySide6.QtWidgets import *
from PySide6.QtGui import *
from PySide6.QtCore import *

class Demo(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.parent = parent
        layout = QVBoxLayout()
        layout.setAlignment(Qt.AlignmentFlag.AlignTop)

        toolBar=QToolBar()
        cb=QCheckBox('Grid')
        cb.stateChanged.connect(self.OnGridVisibleChanged)
        toolBar.addWidget(cb)

        cb=QCheckBox('NavigationBar')
        cb.stateChanged.connect(self.OnNavigationBarVisibleChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('HorizontalHeader:'))
        cb=QComboBox()
        cb.addItems(QCalendarWidget.HorizontalHeaderFormat.__members__.keys())
        cb.currentTextChanged.connect(self.OnHorizontalHeaderFormatChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('VerticalHeader:'))
        cb=QComboBox()
        cb.addItems(QCalendarWidget.VerticalHeaderFormat.__members__.keys())
        cb.currentTextChanged.connect(self.OnVerticalHeaderFormatChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('SelectionMode:'))
        cb=QComboBox()
        cb.addItems(QCalendarWidget.SelectionMode.__members__.keys())
        cb.currentTextChanged.connect(self.OnSelectionModeChanged)
        toolBar.addWidget(cb)

        toolBar.addWidget(QLabel('FirstDayOfWeek:'))
        cb=QComboBox()
        cb.addItems(Qt.DayOfWeek.__members__.keys())
        cb.currentTextChanged.connect(self.OnDayOfWeekChanged)
        toolBar.addWidget(cb)

        layout.addWidget(toolBar)
        
        self.calendar=QCalendarWidget()
        layout.addWidget(self.calendar)

        self.setLayout(layout)
    def OnGridVisibleChanged(self,state):
        self.calendar.setGridVisible(state)
        self.parent.OnShowMessage(f"Set GridVisible={state}")
    def OnNavigationBarVisibleChanged(self,state):
        self.calendar.setNavigationBarVisible(state)
        self.parent.OnShowMessage(f"Set NavigationBarVisible={state}")
    def OnHorizontalHeaderFormatChanged(self,text):
        format=QCalendarWidget.HorizontalHeaderFormat[text]
        self.calendar.setHorizontalHeaderFormat(format)
        self.parent.OnShowMessage(f'Set HorizontalHeaderFormat:{format}')
    def OnVerticalHeaderFormatChanged(self,text):
        format=QCalendarWidget.VerticalHeaderFormat[text]
        self.calendar.setVerticalHeaderFormat(format)
        self.parent.OnShowMessage(f'Set VerticalHeaderFormat:{format}')
    def OnSelectionModeChanged(self,text):
        mode=QCalendarWidget.SelectionMode[text]
        self.calendar.setSelectionMode(mode)
        self.parent.OnShowMessage(f'Set SelectionMode:{mode}')
    def OnDayOfWeekChanged(self,text):
        day=Qt.DayOfWeek[text]
        self.calendar.setFirstDayOfWeek(day)
        self.parent.OnShowMessage(f'Set FirstDayOfWeek:{day}')
def runDemo(parent):
    wigdet =  Demo(parent)
    return wigdet